<?php

namespace App\Http\Controllers\OA;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Logic\ShenPiLogLogic;
use Illuminate\Http\Request;

/**
 * 审批日志记录
 */
class ShenPiLogController extends Controller
{
    protected $logic;

    public function __construct()
    {
        $this->logic = new ShenPiLogLogic();
    }

    //添加日志记录
    public function addShenPiLog(Request $request)
    {
        $rules = [
            'newData'=>'required',//新数据
            'type'=>'required|string',//审批类型
            'fileList'=>'sometimes|nullable|array',//审批文件
            'note'=>'present|nullable|string',//审批备注
            'state'=>'required|in:0,1',//审批状态
        ];
        try{
            $this->checkHeader($request->header());
            $this->verify($request->all(),$rules);
            $params = $this->mergeRequest($request);
            $result = $this->logic->addShenPiLog($params);
            ret_json('ok','请求成功',$result);

        }catch (\Exception $e){
            ret_json('err',$e->getMessage());
        }
    }

    //修改项目角色
    public function editProjectState(Request $request)
    {
        $rules = ['id'=>'required','type'=>'required','state'=>'required|in:0,1'];

        $this->verify($request->all(),$rules);

        $params = $this->mergeRequest($request);

        try{
            $result = $this->logic->editProjectState($params);
            ret_json('ok','审批成功');
        }catch (\Exception $e){
            ret_json('err',$e->getMessage());
        }
    }
}
